from pylab import show
import pandas as pd 
from  pandas import DataFrame
import numpy as np 
from pandas import Series


class Graphy:
	data = {}

	def __init__(self,name):

		self.dict_data = {}
		self.array_data = []
		Graphy.data[name] = self
		self.name = name 
	def add_data(self,key,value):
		if key not in self.dict_data:
			self.dict_data[ key] = [value] 

		self.dict_data [ key ][0] = value  


	def TurnToDataFrame(self):
		return DataFrame(self.dict_data)
		#self.array_data = Series(self.array_data)


	def show(self):
		dict_data = self.TurnToDataFrame()
		print dict_data
		try:
			dict_data.plot(kind='bar')
			dict_data.to_json("./"+self.name+".json")
			show() 
		except AttributeError:
			print "use 'TurnToDataFrame()' method before !!! "




if __name__ == "__main__":
	gg = Graphy('2012')
	gg.add_data('A',12)
	gg.add_data('A',1)
	gg.add_data('B',1)
	gg.add_data('B',1)
	gg.add_data('B',1)
	gg.add_data('B',1)
	gg.add_data('C',1)
	gg.add_data('C',1)
	gg.add_data('C',1)
	gg.add_data('C',1)
	gg.add_data('D',1)
	gg.add_data('D',1)
	gg.add_data('D',1)
	gg.show()
	#gg.add_data('D',2)
	#gg.show()
	while 1:
		pass
